<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\order\PlayOrder;
use app\common\controller\Api;

use app\admin\model\biz\BizInfo;
use app\service\EarningsService;

/**
 * 支付
 */
class Payment extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';


    public function pay(){
        $params=$this->request->post();
        $params['uid']=$this->uid();
        if($params['order_type']==1){
            $result=(new PlayOrder())->pay($params);
        }
        $this->success($result);
    }

    public function notifyx()
    {
        $paytype = $this->request->param('paytype');
        $pay = Service::checkNotify($paytype);
        if (!$pay) {
            echo '签名错误';
            return;
        }
        $data = Service::isVersionV3() ? $pay->callback() : $pay->verify();
        try {
            $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
            $out_trade_no = $data['out_trade_no'];


            //你可以在此编写订单逻辑
        } catch (Exception $e) {
        }

        //下面这句必须要执行,且在此之前不能有任何输出

        if (Service::isVersionV3()) {
            return $pay->success()->getBody()->getContents();
        } else {
            return $pay->success()->send();
        }
    }


    public function fenyong(){

        (new EarningsService())->run(5);

    }
}
